package com.iflysse.controller;

import com.iflysse.common.ResultEnum;
import com.iflysse.pojo.bo.resp.KnowledgePointBoResp;
import com.iflysse.pojo.bo.resp.KnowledgePointListBoResp;
import com.iflysse.pojo.vo.req.KnowledgePointVoReq;
import com.iflysse.pojo.vo.resp.KnowLedgePointResp;
import com.iflysse.pojo.vo.resp.KnowledgePointVoResp;
import com.iflysse.services.IKnowledgePointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/knowLedgePoint")
@Api(value = "老师端知识点的接口")
public class KnowLedgePointController {

    @Autowired
    IKnowledgePointService knowledgePointService;

    @PostMapping("/queryAllKnowLedgePoint")
    @ApiOperation(value = "查询知识点")
    public KnowledgePointVoResp queryAllKnowLedgePoint(KnowledgePointVoReq knowledgePointVoReq) {
        KnowledgePointVoResp knowledgePointVoResp = new KnowledgePointVoResp();
        try{
            KnowledgePointListBoResp knowledgePointListBoResp = IKnowledgePointService.loadAllKnowledgePoints();

            List<KnowledgePointListBoResp> list = knowledgePointListBoResp.getKnowledgePointBoRespList();
            List<KnowLedgePointResp> result = new ArrayList<>();
            for(int i=0;i<list.size();i++){
                KnowledgePointListBoResp knowledgePointBoResp = list.get(i);
                KnowLedgePointResp knowLedgePointResp = new KnowLedgePointResp();
                knowLedgePointResp.setKnowLedgePointId(knowledgePointBoResp.getKnowledgePointId());
                result.add(knowLedgePointResp);
            }
            knowledgePointVoResp.setResult(result);
            //设置返回码和返回信息
            knowledgePointVoResp.setCode(ResultEnum.SUCCESS.getCode());
            knowledgePointVoResp.setMsg(ResultEnum.SUCCESS.getMsg());
        }catch (Exception e){
            e.printStackTrace();
            knowledgePointVoResp.setCode(ResultEnum.ERROR.getCode());
            knowledgePointVoResp.setMsg(ResultEnum.ERROR.getMsg());
        }
        return knowledgePointVoResp;
    }
}